#include<iostream>
#include"comm.hPP"


int main()
{
    std::cout<<"hello clinet!!"<<std::endl;
    std::cout<< "clinet begin"<<std::endl;
    int fd = open(PIPE_PATH, O_WRONLY);//clinet端口是写入数据
    std::cout<< "clinet end"<<std::endl;
    if(fd < 0)
    {
        std::cout<<"error"<<strerror(errno)<<std::endl;
        exit(1);
    }
    
    char buf[1024];
    while(true)
    {
        std::cout<<"please say$";
        fgets(buf, sizeof(buf), stdin);//C语言接口函数，会自己添加 ‘\0’ 
        //buf[strlen(buf) - 1] = 0;//消除末尾的 \n
        if(strlen(buf)>0){buf[strlen(buf) - 1] = 0;}//做一下防御性编程
        
        int s = write(fd, buf,strlen(buf));//写入成功返回写入的字节数，失败返回-1
        assert(s == strlen(buf));
    }
    close(fd);
    return 0;
}